{extend name="Administrator/nav"} 
{block name="title"}学生管理{/block} 
{block name="content"}
<div class="row">
    <div class="col-md-12">
        <div class="container">
            <div class="row">
                <div class="col-md-8">
                    <form class="form-inline" action="{:url()}">
                        <div class="form-group">
                            <label class="sr-only" for="name">学生管理</label>
                            <input name="name" type="text" class="form-control" placeholder="名称..." value="">
                        </div>
                        <button type="submit" class="btn btn-default"><i class="glyphicon glyphicon-search"></i>&nbsp;查询</button>
                    </form>
                </div>
                <div class="col-md-4 text-right">
                    <button class="btn btn-primary" data-toggle="modal" data-target="#mymodal-data"><i class="glyphicon glyphicon-plus"></i>&nbsp;增加</button>
                    <div class="modal" id="mymodal-data" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                    <h4 class="modal-title text-left">增加学生</h4>
                                </div>
                                <div class="modal-body text-left">
                                    <form action="{:url('insert')}" method="post">
                                        <label>学生名字：</label>
                                        <input type="text" name="name">
                                        <label for="class">班级：</label>
                                        <select class="btn btn-default dropdown-toggle" name="klass_id">
                                            {volist name="allklass" id="klass"}
                                            <option value="{$klass->id}">{$klass->name}</option>
                                            {/volist}
                                        </select>
                                        <button type="submit" class="btn btn-primary">保存</button>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <hr />
            <table class="table table-hover table-bordered">
                <tr class="info">
                    <th width="10%">ID</th>
                    <th width="35%">学生名字</th>
                    <th width="35%">所属班级</th>
                    <th width="20%">操作</th>
                </tr>
                {volist name="students" id="student" key="key"}
                <tr>
                    <td>{$key}</td>
                    <td>{$student->getData('name')}</td>
                    <td>{$student->Klass->getData('name')}</td>
                    <td><a class="btn btn-sm btn-danger" href="{:url('delete?id=' . $student->getData('id'))}"><i class="glyphicon glyphicon-trash"></i>&nbsp;删除</a>
                        <button type="button"  class="btn btn-sm btn-primary"  data-toggle="modal" data-target=".bs-example-modal-lg{$key}"><i class="glyphicon glyphicon-pencil"></i>&nbsp;编辑</button>
                        <div class="modal fade bs-example-modal-lg{$key}" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
                            <div class="modal-dialog modal-lg{$key}" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                                        <h4 class="modal-title">编辑学生</h4>
                                    </div>
                                    <div class="modal-body">
                                        <form action="{:url('update')}" method="post">
                                            <label>学生名字：</label>
                                            <input type="hidden" name="id" value="{$student->getData('id')}" />
                                            <input type="text" name="name" id="name" value="{$student->getData('name')}">
                                            <label for="class">班级：</label>
                                            <select class="btn btn-default dropdown-toggle" name="klass_id">
                                                {volist name="allklass" id="klass"}
                                                <option value="{$klass->id}"  {eq name="$student->Klass->getData('id')" value="$klass->getData('id')" } selected="selected" {/eq}>{$klass->name}</option>
                                                {/volist}
                                            </select>
                                            <button type="submit" class="btn btn-primary">保存</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
                {/volist}
            </table>
            {:$students->render()}
        </div>
    </div>
</div>
{/block}